package com.ruoyi.system.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysLeaveRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.ISysLeaveRequestService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请假申请】Controller
 * 
 * @author ruoyi
 * @date 2024-07-20
 */
@RestController
@RequestMapping("/request")
public class SysLeaveRequestController extends BaseController {
    @Autowired
    private ISysLeaveRequestService sysLeaveRequestService;


    /**
     * 查询【请假申请】列表
     */
    @RequiresPermissions("system:request:list")
    @GetMapping("/list")
    public TableDataInfo list(SysLeaveRequest sysLeaveRequest) {
        startPage();
        List<SysLeaveRequest> list = sysLeaveRequestService.selectSysLeaveRequestList(sysLeaveRequest);
        return getDataTable(list);
    }

    /**
     * 导出【请假申请】列表
     */
    @RequiresPermissions("system:request:export")
    @Log(title = "【请假申请】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysLeaveRequest sysLeaveRequest)
    {
        List<SysLeaveRequest> list = sysLeaveRequestService.selectSysLeaveRequestList(sysLeaveRequest);
        ExcelUtil<SysLeaveRequest> util = new ExcelUtil<SysLeaveRequest>(SysLeaveRequest.class);
        util.exportExcel(response, list, "【请假申请】数据");
    }

    /**
     * 获取【请假申请】详细信息
     */
    @RequiresPermissions({"system:request:check"})
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId) {
        return success(sysLeaveRequestService.selectSysLeaveRequestByRequestId(requestId));
    }

    /**
     * 新增【请假申请】
     */
    @RequiresPermissions("system:request:add")
    @Log(title = "【请假申请】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysLeaveRequest sysLeaveRequest) {
        return toAjax(sysLeaveRequestService.insertSysLeaveRequest(sysLeaveRequest));
    }

    /**
     * 修改【请假申请】
     */
    @RequiresPermissions("system:request:edit")
    @Log(title = "【请假申请】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysLeaveRequest sysLeaveRequest)
    {
        sysLeaveRequest.setUpdateBy(SecurityUtils.getUsername());
        sysLeaveRequest.setUpdateTime(new Date());
        return toAjax(sysLeaveRequestService.updateSysLeaveRequest(sysLeaveRequest));
    }

    /**
     * 删除【请假申请】
     */
    @RequiresPermissions("system:request:remove")
    @Log(title = "【请假申请】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(sysLeaveRequestService.deleteSysLeaveRequestByRequestIds(requestIds));
    }

    /**
     * 审核【请假申请】
     */
    @GetMapping("/go/check")
    public AjaxResult goCheck(@RequestParam("requestId")Long requestId,@RequestParam("status")String status){
        System.err.println(requestId);
        System.err.println(status);
        return toAjax(sysLeaveRequestService.goCheck(requestId,status));
    }

    /**
     * 待办【请假申请】
     */
    @GetMapping("/wait/check")
    public TableDataInfo leaveWaitCheck(){
        return getDataTable(sysLeaveRequestService.leaveWaitCheck());
    }

    /**
     * 审核人下拉框【请假申请】
     */
    @GetMapping("/approver")
    public TableDataInfo selectApprover(){
        return getDataTable(sysLeaveRequestService.selectApprover());
    }
}
